/**
	Copyright (c) 2011 ATTi 
	All rights reserved.
	Author: Michael Shu
	Purpose : Copy Account team to case fields.
	Project : NADM, NATO, NATL
	Date: 3/10/2011
*/

trigger CaseAASFieldUpdateTrigger on Case (before insert, before update) {
	if(trigger.isBefore){
		list<Case> cases = new list<Case>();
		set<ID> caseNATORecordTypeID = OppForNatSalesHelperClass.getCaseNATORecordTypeID();
		if(trigger.isInsert){
			for(Case c : trigger.new){
				if(caseNATORecordTypeID.contains(c.RecordTypeId)){
					cases.add(c);
				}	
			}
		}else if(trigger.isUpdate){
			for(Case c : trigger.new){
				Case oldcs = trigger.oldMap.get(c.Id);
				if(oldcs.AccountId != c.AccountId && caseNATORecordTypeID.contains(c.RecordTypeId) ){
					cases.add(c);
				}	
			}
		}
		if(!cases.isEmpty()){
			OppForNatSalesHelperClass.updateCasefieldsFromAccountTeams(cases);
		}
	}
}